<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddDealerIdToUserCouponsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('user_coupons', function (Blueprint $table) {
            $table->bigInteger('dealer_id')->unsigned()->comment('核销经销商ID')->after('used_at');
            $table->foreign('dealer_id')->references('id')->on('dealers')->onDelete('restrict');
            $table->dropColumn('dealer');
            $table->dropColumn('dealer_code');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('user_coupons', function (Blueprint $table) {
            $table->dropColumn('dealer_id');
            $table->string('dealer',255)->nullable()->comment('核销经销商');
            $table->string('dealer_code',20)->nullable()->comment('核销经销商代码');
        });
    }
}
